package fun.wlfj.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import fun.wlfj.dao.ICashDao;
import fun.wlfj.dbc.IConnectionManager;
import fun.wlfj.dbc.MySQLConnection;
import fun.wlfj.vo.Cash;

public class CashDaoImpl extends AbsDaoImpl implements ICashDao  {

	public CashDaoImpl(Connection conn) {
		super(conn);
	}

	@Override
	public List<Cash> getCashList() {
		List<Cash> list = new LinkedList<Cash>();
		PreparedStatement pstsm = null;
		try {
			pstsm = conn.prepareStatement("select * from CashList;");
			ResultSet rs = pstsm.executeQuery();
			while(rs.next()) {
				list.add(new Cash(rs.getInt(1), rs.getInt(2), rs.getDouble(3), rs.getDate(4), rs.getString(5)));
			}
			IConnectionManager.closePstsm(pstsm);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	
	public static void main(String[] args) {
		IConnectionManager manager = new MySQLConnection();
		CashDaoImpl testdao = new CashDaoImpl(manager.getConn());
		List<Cash> cashList = testdao.getCashList();
		System.err.println("测试Cash功能");
		for(Cash c : cashList) {
			System.out.println(c);
		}
		manager.closeAll(null);
	}

}
